//
//  CPTabbarController.m
//  CPApp
//
//  Created by 健健 on 2018/3/21.
//  Copyright © 2018年 Class. All rights reserved.
//

#import "CPTabbarController.h"
#import "CPNavigationController.h"
#import "CPHomeVC.h"
#import "CPPredictVC.h"
#import "CPColorMessageVC.h"
#import "CPMineVC.h"

@interface CPTabbarController ()

@end

@implementation CPTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [UINavigationBar appearance];
    // Do any additional setup after loading the view.
    self.tabBar.viewForFirstBaselineLayout.backgroundColor = [UIColor whiteColor];
    
    [self addChildVc:[[CPHomeVC alloc]init] title:@"首页" image:@"icon nor" selectedImage:@"icon sel"];
    
    [self addChildVc:[[CPPredictVC alloc]init] title:@"本期预测" image:@"predict" selectedImage:@"predict_selecte"];
    
    [self addChildVc:[[CPColorMessageVC alloc]init] title:@"彩讯" image:@"color_selecte" selectedImage:@"color"];
    
    CPMineVC * vc = [[UIStoryboard storyboardWithName:@"Mine" bundle:nil]instantiateViewControllerWithIdentifier:@"MineSB"];
    [self addChildVc:vc title:@"我" image:@"mine" selectedImage:@"mine_selects"];
    
}
- (void)addChildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage {
    // 先给外面传进来的小控制器 包装 一个导航控制器
    CPNavigationController *nav = [[CPNavigationController alloc] initWithRootViewController:childVc];
    nav.tabBarController.tabBar.backgroundColor = HJMainColor;
    childVc.navigationItem.title = nil;
    // 设置子控制器的文字
    childVc.tabBarItem.title = title; // 设置tabbar的文字
    
    // 设置子控制器的图片
    if (iOS7) {
        childVc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    } else {
        childVc.tabBarItem.image = [UIImage imageNamed:image];
        childVc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    }
    childVc.tabBarItem.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    
    // 设置文字的样式
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    textAttrs[NSFontAttributeName] = HJFontSize(12);
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = HJColor(240, 8, 7);
    selectTextAttrs[NSFontAttributeName] = HJFontSize(12);
    [nav.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [nav.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
    // 添加为子控制器
    [self addChildViewController:nav];
}



@end
